package com.jkoss.wine.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jkoss.common.util.CommonUtil;
import com.jkoss.wine.system.entity.MerchantEmployeesRole;
import com.jkoss.wine.system.mapper.MerchantEmployeesRoleMapper;
import com.jkoss.wine.system.service.IMerchantEmployeesRoleService;

/**
 * <p>
 * 用户角色 服务实现类
 * </p>
 *
 * @author Jason
 * @since 2018-09-21
 */
@Service
public class MerchantEmployeesRoleServiceImpl extends ServiceImpl<MerchantEmployeesRoleMapper, MerchantEmployeesRole> implements IMerchantEmployeesRoleService {
	@Override
	public List<String> selectRidByMeid(String id) {
		return this.baseMapper.selectRidByMeid(id);
	}

	@Override
	public boolean updateRole(String id, String[] rid) {
		// 删除所有用户角色
		Wrapper wrapper = Condition.create().eq("meid", id);
		this.baseMapper.delete(wrapper);
		if (!CommonUtil.isBlank(rid)) {
			List<MerchantEmployeesRole> rolePermissions = new ArrayList();
			for (String ridStr : rid) {
				MerchantEmployeesRole tpEmployRole = new MerchantEmployeesRole();
				tpEmployRole.setMeid(id);
				tpEmployRole.setRid(ridStr);
				rolePermissions.add(tpEmployRole);
			}
			return this.insertBatch(rolePermissions);
		} else {
			return true;
		}
	}

	@Override
	public List selectMerchantEmployeesRole(String id) {
		return baseMapper.selectMerchantEmployeesRole(id);
	}

}
